<?php

	include("php/db.php");

	$conn = new Conexao();
	$conn->open();

	$querystring = '
		SELECT ct.id, ct.justification, places.name, places.category, comments.date AS data
		FROM comments_tickets as ct
		INNER JOIN comments
		ON ct.comment_id = comments.id
		INNER JOIN places
		ON comments.place_id = places.id
		ORDER BY date';
	$query = pg_query($querystring);
	$nrows = pg_num_rows($query); 

	if ( $nrows == 0) {
		print "Não há denúncias de comentários.";
	}

	else{
?>
	<table class="table" cellspacing="0"> <!-- to create a darker table row, you must add the class even to a tr eg. <tr class="even">…</tr> -->

		<!-- Table Header --> 
		<tbody> 
			<tr> 
			<th>Data</th> 
			<th>Local</th> 
			<th>Categoria</th>
			<th>Problema</th>
			<th>Ação</th>  
			</tr> 
		<!-- Table Header -->

			<?php
				$i = 0;
				while ($arr = pg_fetch_array($query,$i)){

					if (($i%2) == 0){
						print "<tr>";
					} else {
						print "<tr class='even'>";
					}

					print "<td>".date('d/m/Y', strtotime($arr['data']))."</td>";
					print "<td>".$arr["name"]."</td>";
					print "<td>".$arr["category"]."</td>";
					print "<td>".$arr["justification"]."</td>";
					print "<td><a href='javascript:editcomment(".$arr["id"].")'>Editar</a></td>";

					print "</tr>";

					if ( ($i+1) < $nrows ) {
						$i = $i+1;
					} else {
						return;
					}

				}
			?>

		</tbody> </table>

<?php

	}
	$conn->close();
?>